package com.baizhi.controller;


import com.baizhi.entity.LayuiRole;
import com.baizhi.entity.LayuiRoleResource;
import com.baizhi.service.LayuiRoleResourceService;
import com.baizhi.service.LayuiRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengg
 * @since 2020-07-31
 */
@RestController
@RequestMapping("/layui-role")
public class LayuiRoleController {
    @Autowired
    private LayuiRoleService rs;
    @RequestMapping("/select")
    public List<LayuiRole> selectAll(){
        return rs.list();
    }
    @Autowired
    private LayuiRoleResourceService lrrs;
    @RequestMapping("/grantResource")
    public Map<String,Object> grantResource(Integer roleId, @RequestParam("resourceIds") List<Integer> resourceIds){
        for(Integer rid:resourceIds){
            LayuiRoleResource lrr=new LayuiRoleResource(roleId,rid);
            lrrs.save(lrr);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        return map;
    }
}
